
package com.starshineworks.util.actions;

import com.starshineworks.entities.*;

import java.util.Map;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ActionInfo extends Action {
    
    @Override
    public boolean perform(HttpServletRequest  request, 
                           HttpServletResponse resp,
                           HttpServlet         serv, 
                           boolean             isMultiPart)
    {
        Map<String,String[]> map = request.getParameterMap();
        HttpSession sess = request.getSession();
        Integer uId = (Integer)sess.getAttribute("uId");        
        if (uId != null) {
            UserinfoE ui = (UserinfoE)UserinfoE.retrieveByUser(uId);
            EntityE.updateObjectFields(ui, map);            
            // After updating the DB, re-load the modified object.
            ui = (UserinfoE)UserinfoE.retrieveByUser(uId);            
            sess.setAttribute("fullName", ui.fullName());
            return true;
        }
        return false;
    }

    @Override
    public String getNextPage() {
        return "User";
    }
    
}
